import {
  ChangeDetectionStrategy,
  Component,
  Input,
  OnChanges,
  OnInit,
  SimpleChanges,
  ViewEncapsulation,
} from '@angular/core';
import { InputBoolean } from '../utils/convert';

@Component({
  selector: 'lv-select-trigger-icon',
  templateUrl: './select-trigger-icon.component.html',
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    class: 'lv-select-trigger-icon',
    '[class.lv-select-trigger-icon-open]': 'openState',
    '[class.lv-select-trigger-icon-close]': 'openState === false',
  },
})
export class SelectTriggerIconComponent implements OnInit, OnChanges {
  @Input() @InputBoolean() lvOpen;
  @Input() @InputBoolean() lvDisabled: boolean | string = false;

  openState: boolean;

  constructor() {}

  ngOnInit(): void {}

  ngOnChanges(changes: SimpleChanges): void {
    const { lvOpen: open } = changes;

    if (Boolean(open.currentValue) !== Boolean(open.previousValue)) {
      this.openState = open.currentValue;
    }
  }
}
